/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edu.kamai.client.control;


import com.edu.kamai.webservice.client.WSContestClient;
import com.edu.kamai.webservice.contest.Contest;
import java.util.List;

/**
 *
 * @author xyzhu
 */
public class contestControl {
    private static List<String> netList;
    private static String message;
    private static WSContestClient wsContestClient; 
    
    public static String getMessage() {
        return message;
    }

    public static void setMessage(String message) {
        contestControl.message = message;
    }

    public static List<String> getNetList() {
        return netList;
    }

    public static void setNetList(List<String> netList) {
        contestControl.netList = netList;
    }
    
    public static void setServer(){
        try{
            wsContestClient = new WSContestClient();
            
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public static int addContest(String cTitle,String cDesc,String uID,int rID,
            int sID,int wID,int lID){
        int ans;
        try{
            ans = wsContestClient.addContest(cTitle, cDesc, uID, rID, sID, wID, lID);
            if (ans == 1) {
                message = "Add Contest OK!";
            } else {
                message = "Add Contest Failed!";
            }
        }catch(Exception ex){
            ans = 0;
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return ans;
    }
    
    public static List<Contest> findContest(){
        //int ans;
        List<Contest> contests=null;
        try{
            contests = wsContestClient.findContest();
            if(contests.size() == 0 || contests == null){
                message = "no contest!";
            }else{
                message = "all " + contests.size() + " contests";
            }
        }catch(Exception ex){
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        
        return contests;
    }
    
    public static Contest findContestByID(int cid){
        Contest contest = null;
        try{
            contest = wsContestClient.findContestById(cid);
            if(contest == null){
                message = "no contest!";
            }else{
                message = "get contest ok!";
            }
        }catch(Exception ex){
            message = "Connect Server Error!";
            ex.printStackTrace();
        }
        return contest;
    }
    
}
